package cn.fleamarket.cache;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * @author zyc
 * @date 2022/5/28 11:44
    需要添加的依赖
        <!--Redis的依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
 */
@Configuration
public class RedisConfig {

    @Bean
    RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(factory);
        // 手动指定key的序列化方式是string
        template.setKeySerializer(RedisSerializer.string());
        // 设置value的序列化方式是json,可选类型有string/json/java
        template.setValueSerializer(RedisSerializer.java());
        return template;
    }

}
